﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.Revit;
using HYElectricKernel;

namespace YArchitech.Plumbing
{
	public class RectLayPoint
	{
		public List<List<XYZ>> PointSet
		{
			get
			{
				return this.pointSet;
			}
		}

		public List<XYZ> Points
		{
			get
			{
				return this.points;
			}
		}

		public XYZ PointEnd
		{
			get
			{
				return this.point2;
			}
		}

		public RectLayPoint(RectLayParamers paras)
		{
			this.rectLayParamers = paras;
			if (this.rectLayParamers.LessDistance > 0.0 || this.rectLayParamers.BeiShu > 0)
			{
				this.Calc(1);
				return;
			}
			this.Calc();
		}

		private void Calc()
		{
			if (this.rectLayParamers.LayType == 0)
			{
				this.rectNum = new RectLayoutNum(this.rectLayParamers);
				this.pointSet = this.rectNum.CalcInsertPoints();
				return;
			}
			this.rectDis = new RectLayoutDis(this.rectLayParamers);
			this.pointSet = this.rectDis.CalcInsertPoints();
		}

		private void Calc(int N)
		{
			double num = Func.AngleToRadian(this.rectLayParamers.AngleRow);
			XYZ xyz = Geometry.RotateTo(this.rectLayParamers.PointDiagonal, this.rectLayParamers.PointBase, XYZ.BasisZ, -num);
			this.rectLayParamers.XDiagonalPoint = new XYZ(xyz.X, this.rectLayParamers.PointBase.Y, xyz.Z);
			this.rectLayParamers.YDiagonalPoint = new XYZ(this.rectLayParamers.PointBase.X, xyz.Y, xyz.Z);
			this.point2 = Geometry.RotateTo(this.rectLayParamers.XDiagonalPoint, this.rectLayParamers.PointBase, XYZ.BasisZ, num);
			if (this.point2.IsAlmostEqualTo(this.rectLayParamers.PointBase))
			{
				this.points = null;
				return;
			}
			ConnectHelper connectHelper = new ConnectHelper();
			if (this.rectLayParamers.LayType == 0)
			{
				this.points = connectHelper.CalculateLayFamilyInstanceXYZ(this.rectLayParamers.PointBase, this.point2, this.rectLayParamers.PointDiagonal, this.rectLayParamers.RowCount, this.rectLayParamers.ColCount, this.rectLayParamers.Margin, 0.0);
				return;
			}
			this.points = connectHelper.CalculateLaySprinklersXYZ(this.rectLayParamers.PointBase, this.point2, this.rectLayParamers.PointDiagonal, this.rectLayParamers.XSpace, this.rectLayParamers.YSpace, this.rectLayParamers.XMargin, this.rectLayParamers.YMargin, this.rectLayParamers.LessDistance, 0.0, this.rectLayParamers.BeiShu);
		}

		private RectLayParamers rectLayParamers;

		private RectLayoutDis rectDis;

		private RectLayoutNum rectNum;

		private List<List<XYZ>> pointSet;

		private List<XYZ> points;

		private XYZ point2;
	}
}
